package com.my_musc_service.utils;

import org.apache.commons.lang3.StringUtils;

import java.io.File;

/**
 * @author Zhu Dunfeng
 * @date 2021/8/19 21:14
 */

public class UploadFileUtils {

    public static void deleteFile(String uploadPath,String fileUrl) {
        //删除歌词
        //兼容版本
        if (StringUtils.isNotBlank(fileUrl)) {
            String fileUri = getFileUri(fileUrl);
            String filePath = uploadPath + "/" + fileUri;
            File file = new File(filePath);
            if (file.exists()) {
                file.delete();
            }
        }
    }

    public static String getFileUri(String url) {
        String uri = null;
        if (url.contains("music")) {
            uri = url.substring(url.lastIndexOf("music") + 6);
        } else {
            uri = url.substring(url.lastIndexOf("9000") + 5);
        }
        return uri;
    }
}
